/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sober.criteria;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User:chenYuan (mail:39793751@qq.com)
 * Date: 2007-1-8
 * Time: 10:13:54
 */
public class Order implements Serializable
{
    //排序
    private boolean ascending;
    //排序字段
    private String propertyName;

    public String toString()
    {
        return propertyName + " " + (ascending ? "asc" : "desc");
    }

    public Order ignoreCase()
    {
        return this;
    }

    /**
     * Constructor for Order.
     */
    protected Order(String propertyName, boolean ascending)
    {
        this.propertyName = propertyName;
        this.ascending = ascending;
    }

    /**
     * 先序
     *
     * @param propertyName
     * @return Order
     */
    public static Order asc(String propertyName)
    {
        return new Order(propertyName, true);
    }

    /**
     * 后序
     *
     * @param propertyName
     * @return Order
     */
    public static Order desc(String propertyName)
    {
        return new Order(propertyName, false);
    }


    public String[] getFields()
    {
        return new String[]{propertyName};
    }

}